package com.yc.book;

import com.yc.book.dao.BookDao;
import com.yc.book.util.Utils;
import com.yc.common.bean.Result;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

import java.io.IOException;

@WebServlet(name = "RemoveBookServlet", value = "/remove.s")
public class RemoveBookServlet extends HttpServlet {
    private BookDao dao = new BookDao();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        Result res;
        try {
            dao.delete(id);
            res = Result.success("删除成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            res = Result.failure("删除失败！请联系管理员！", null);
        }
        Utils.writeJson(res, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
